Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce recv_blocking() method on PayloadReceiver #153

Merged
merged 1 commit into from
Mar 15, 2023

Conversation

strohel
Copy link
Member

@strohel strohel commented Mar 11, 2023

Allows callers to wait for a frame without using futures. Turned out async_channel::Receiver already had a recv_blocking() method, so this is rather straightforward.

In addition to the API changes, update READMEs and example to use the new method. The version in current main does a busy loop (consumes 100% of its CPU thread).

Best viewed with whitespace change ignored.

This is yet to be tested with a real camera (:pray: :pray: @bschwind).

  • Check test_all.sh is passed.
  • Add fix #{ISSUE_NUMBER} if the corresponding issue exists.
  • Fill out ## Changelog section. If the change is for only internal use, please write None to the section.

Changelog

  • recv_blocking() method was introduced on PayloadReceiver. It allows callers to wait for a frame without using futures.

Copy link
Member

@Y-Nak Y-Nak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!
I tested this locally, and run well.

Nit: Could you update async-std dependency to 1.12.0?

@Y-Nak
Copy link
Member

Y-Nak commented Mar 12, 2023

@bschwind Could you review and merge the PR if it's ok?

I totally agree to update the version after the PR is merged.

@strohel
Copy link
Member Author

strohel commented Mar 12, 2023

Nit: Could you update async-std dependency to 1.12.0?

Done. Was the intent to make sure that .recv_blocking() exists? I see it was added in async-channel 1.7.0, but even async-std 1.12 only requires async-channel 1.5.1.

But perhaps we don't have to worry too much - and I also plan to be touching this in another PR.

@Y-Nak
Copy link
Member

Y-Nak commented Mar 12, 2023

Oops, it's true. Sorry for the additional work.

@bschwind
Copy link
Contributor

bschwind commented Mar 13, 2023

Strange, when I run test_all.sh, I get errors:

cameleon $ ./test_all.sh             
    Checking cameleon v0.1.8 (/Users/brian/projects/cameleon/cameleon)
error[E0599]: no method named `recv_blocking` found for struct `async_std::channel::Receiver` in the current scope
   --> cameleon/src/payload.rs:128:17
    |
128 |         self.rx.recv_blocking()?
    |                 ^^^^^^^^^^^^^ method not found in `async_std::channel::Receiver<std::result::Result<payload::Payload, StreamError>>`

For more information about this error, try `rustc --explain E0599`.
error: could not compile `cameleon` due to previous error
warning: build failed, waiting for other jobs to finish...
error: could not compile `cameleon` due to previous error

This is on commit d7caba6

Edit: Ah, I ran a cargo clean and that seemed to fix it.

@bschwind
Copy link
Contributor

With a real camera attached, I get 3 test failures, but these also happened in main so not related to this PR.

The camera is an IDS U3-3881LE-C-HQ Rev 1.2

running 18 tests
test src/camera.rs - camera (line 8) ... ok
test src/camera.rs - camera::Camera (line 72) ... ok
test src/camera.rs - camera::Camera<Ctrl,Strm,Ctxt>::close (line 184) ... ok
test src/camera.rs - camera::Camera<Ctrl,Strm,Ctxt>::convert_into (line 477) ... ok
test src/camera.rs - camera::Camera<Ctrl,Strm,Ctxt>::info (line 432) ... ok
test src/camera.rs - camera::Camera<Ctrl,Strm,Ctxt>::load_context (line 224) ... ok
test src/camera.rs - camera::Camera<Ctrl,Strm,Ctxt>::open (line 150) ... ok
test src/camera.rs - camera::Camera<Ctrl,Strm,Ctxt>::params_ctxt (line 380) ... FAILED
test src/camera.rs - camera::Camera<Ctrl,Strm,Ctxt>::start_streaming (line 263) ... ok
test src/camera.rs - camera::Camera<Ctrl,Strm,Ctxt>::stop_streaming (line 329) ... ok
test src/genapi/mod.rs - genapi (line 8) ... FAILED
test src/genapi/mod.rs - genapi::ParamsCtxt (line 70) ... FAILED
test src/lib.rs - (line 31) ... ok
test src/u3v/control_handle.rs - u3v::control_handle::ControlHandle (line 44) - compile ... ok
test src/u3v/mod.rs - u3v (line 9) - compile ... ok
test src/u3v/mod.rs - u3v::enumerate_cameras (line 67) - compile ... ok
test src/u3v/register_map.rs - u3v::register_map (line 12) - compile ... ok
test src/u3v/register_map.rs - u3v::register_map::Abrm (line 67) - compile ... ok

failures:

---- src/camera.rs - camera::Camera<Ctrl,Strm,Ctxt>::params_ctxt (line 380) stdout ----
Test executable failed (exit status: 101).

stdout:
1

stderr:
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Device(Io(invalid status: GenCp(InvalidParameter)))', src/camera.rs:31:48
stack backtrace:
   0:        0x1003cd810 - std::backtrace_rs::backtrace::libunwind::trace::hf9c5171f212b04e2
                               at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:        0x1003cd810 - std::backtrace_rs::backtrace::trace_unsynchronized::h179003f6ec753118
                               at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:        0x1003cd810 - std::sys_common::backtrace::_print_fmt::h92d38f701cf42b17
                               at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/std/src/sys_common/backtrace.rs:65:5
   3:        0x1003cd810 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hb33e6e8152f78c95
                               at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/std/src/sys_common/backtrace.rs:44:22
   4:        0x1003e4bac - core::fmt::write::hd33da007f7a27e39
                               at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/core/src/fmt/mod.rs:1208:17
   5:        0x1003cb788 - std::io::Write::write_fmt::h7edc10723862001e
                               at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/std/src/io/mod.rs:1682:15
   6:        0x1003cd624 - std::sys_common::backtrace::_print::h5e00f05f436af01f
                               at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/std/src/sys_common/backtrace.rs:47:5
   7:        0x1003cd624 - std::sys_common::backtrace::print::h895ee35b3f17b334
                               at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/std/src/sys_common/backtrace.rs:34:9
   8:        0x1003ced98 - std::panicking::default_hook::{{closure}}::h3b7ee083edc2ea3e
                               at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/std/src/panicking.rs:267:22
   9:        0x1003ceaf0 - std::panicking::default_hook::h4e7c2c28eba716f5
                               at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/std/src/panicking.rs:286:9
  10:        0x1003cf3bc - std::panicking::rust_panic_with_hook::h1672176227032c45
                               at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/std/src/panicking.rs:688:13
  11:        0x1003cf1dc - std::panicking::begin_panic_handler::{{closure}}::h0b2d072f9624d32e
                               at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/std/src/panicking.rs:579:13
  12:        0x1003cdc78 - std::sys_common::backtrace::__rust_end_short_backtrace::he9abda779115b93c
                               at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/std/src/sys_common/backtrace.rs:137:18
  13:        0x1003cef38 - rust_begin_unwind
                               at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/std/src/panicking.rs:575:5
  14:        0x1003f20bc - core::panicking::panic_fmt::h23ae44661fec0889
                               at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/core/src/panicking.rs:64:14
  15:        0x1003f2394 - core::result::unwrap_failed::h414a6cbb12b1e143
                               at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/core/src/result.rs:1791:5
  16:        0x1001c9c8c - core::result::Result<T,E>::unwrap::h585300c727446024
  17:        0x1001f3600 - rust_out::main::_doctest_main_src_camera_rs_380_0::h726360edda07a72c
  18:        0x1001f32e8 - rust_out::main::ha12cc177fff9511c
  19:        0x1001c3270 - core::ops::function::FnOnce::call_once::h84bb37f27cbfcd8f
  20:        0x1001c1d40 - std::sys_common::backtrace::__rust_begin_short_backtrace::h813ad797d3d37f95
  21:        0x1001c1e74 - std::rt::lang_start::{{closure}}::h8bfb5e6da05388a2
  22:        0x1003c8a94 - core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &F>::call_once::ha1c2447b9b665e13
                               at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/core/src/ops/function.rs:606:13
  23:        0x1003c8a94 - std::panicking::try::do_call::ha57d6d1e9532dc1f
                               at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/std/src/panicking.rs:483:40
  24:        0x1003c8a94 - std::panicking::try::hca0526f287961ecd
                               at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/std/src/panicking.rs:447:19
  25:        0x1003c8a94 - std::panic::catch_unwind::hdcaa7fa896e0496a
                               at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/std/src/panic.rs:137:14
  26:        0x1003c8a94 - std::rt::lang_start_internal::{{closure}}::h142ec071d3766871
                               at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/std/src/rt.rs:148:48
  27:        0x1003c8a94 - std::panicking::try::do_call::h95f5e55d6f048978
                               at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/std/src/panicking.rs:483:40
  28:        0x1003c8a94 - std::panicking::try::h0fa00e2f7b4a5c64
                               at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/std/src/panicking.rs:447:19
  29:        0x1003c8a94 - std::panic::catch_unwind::h1765f149814d4d3e
                               at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/std/src/panic.rs:137:14
  30:        0x1003c8a94 - std::rt::lang_start_internal::h00a235e820a7f01c
                               at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/std/src/rt.rs:148:20
  31:        0x1001c1e4c - std::rt::lang_start::h6ff56b89212eb3b9
  32:        0x1001f3664 - _main


---- src/genapi/mod.rs - genapi (line 8) stdout ----
Test executable failed (exit status: 101).

stdout:
1

stderr:
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Device(Io(invalid status: GenCp(InvalidParameter)))', src/genapi/mod.rs:30:48
stack backtrace:
   0:        0x10512d810 - std::backtrace_rs::backtrace::libunwind::trace::hf9c5171f212b04e2
                               at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:        0x10512d810 - std::backtrace_rs::backtrace::trace_unsynchronized::h179003f6ec753118
                               at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:        0x10512d810 - std::sys_common::backtrace::_print_fmt::h92d38f701cf42b17
                               at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/std/src/sys_common/backtrace.rs:65:5
   3:        0x10512d810 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hb33e6e8152f78c95
                               at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/std/src/sys_common/backtrace.rs:44:22
   4:        0x105144bac - core::fmt::write::hd33da007f7a27e39
                               at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/core/src/fmt/mod.rs:1208:17
   5:        0x10512b788 - std::io::Write::write_fmt::h7edc10723862001e
                               at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/std/src/io/mod.rs:1682:15
   6:        0x10512d624 - std::sys_common::backtrace::_print::h5e00f05f436af01f
                               at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/std/src/sys_common/backtrace.rs:47:5
   7:        0x10512d624 - std::sys_common::backtrace::print::h895ee35b3f17b334
                               at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/std/src/sys_common/backtrace.rs:34:9
   8:        0x10512ed98 - std::panicking::default_hook::{{closure}}::h3b7ee083edc2ea3e
                               at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/std/src/panicking.rs:267:22
   9:        0x10512eaf0 - std::panicking::default_hook::h4e7c2c28eba716f5
                               at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/std/src/panicking.rs:286:9
  10:        0x10512f3bc - std::panicking::rust_panic_with_hook::h1672176227032c45
                               at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/std/src/panicking.rs:688:13
  11:        0x10512f1dc - std::panicking::begin_panic_handler::{{closure}}::h0b2d072f9624d32e
                               at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/std/src/panicking.rs:579:13
  12:        0x10512dc78 - std::sys_common::backtrace::__rust_end_short_backtrace::he9abda779115b93c
                               at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/std/src/sys_common/backtrace.rs:137:18
  13:        0x10512ef38 - rust_begin_unwind
                               at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/std/src/panicking.rs:575:5
  14:        0x1051520bc - core::panicking::panic_fmt::h23ae44661fec0889
                               at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/core/src/panicking.rs:64:14
  15:        0x105152394 - core::result::unwrap_failed::h414a6cbb12b1e143
                               at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/core/src/result.rs:1791:5
  16:        0x104f29c8c - core::result::Result<T,E>::unwrap::h585300c727446024
  17:        0x104f53600 - rust_out::main::_doctest_main_src_genapi_mod_rs_8_0::h3ead0f967807e45b
  18:        0x104f532e8 - rust_out::main::ha12cc177fff9511c
  19:        0x104f23270 - core::ops::function::FnOnce::call_once::h84bb37f27cbfcd8f
  20:        0x104f21d40 - std::sys_common::backtrace::__rust_begin_short_backtrace::h813ad797d3d37f95
  21:        0x104f21e74 - std::rt::lang_start::{{closure}}::h8bfb5e6da05388a2
  22:        0x105128a94 - core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &F>::call_once::ha1c2447b9b665e13
                               at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/core/src/ops/function.rs:606:13
  23:        0x105128a94 - std::panicking::try::do_call::ha57d6d1e9532dc1f
                               at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/std/src/panicking.rs:483:40
  24:        0x105128a94 - std::panicking::try::hca0526f287961ecd
                               at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/std/src/panicking.rs:447:19
  25:        0x105128a94 - std::panic::catch_unwind::hdcaa7fa896e0496a
                               at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/std/src/panic.rs:137:14
  26:        0x105128a94 - std::rt::lang_start_internal::{{closure}}::h142ec071d3766871
                               at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/std/src/rt.rs:148:48
  27:        0x105128a94 - std::panicking::try::do_call::h95f5e55d6f048978
                               at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/std/src/panicking.rs:483:40
  28:        0x105128a94 - std::panicking::try::h0fa00e2f7b4a5c64
                               at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/std/src/panicking.rs:447:19
  29:        0x105128a94 - std::panic::catch_unwind::h1765f149814d4d3e
                               at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/std/src/panic.rs:137:14
  30:        0x105128a94 - std::rt::lang_start_internal::h00a235e820a7f01c
                               at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/std/src/rt.rs:148:20
  31:        0x104f21e4c - std::rt::lang_start::h6ff56b89212eb3b9
  32:        0x104f53664 - _main


---- src/genapi/mod.rs - genapi::ParamsCtxt (line 70) stdout ----
Test executable failed (exit status: 101).

stdout:
1

stderr:
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Device(Io(invalid status: GenCp(InvalidParameter)))', src/genapi/mod.rs:30:48
stack backtrace:
   0:        0x1010ed810 - std::backtrace_rs::backtrace::libunwind::trace::hf9c5171f212b04e2
                               at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:        0x1010ed810 - std::backtrace_rs::backtrace::trace_unsynchronized::h179003f6ec753118
                               at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:        0x1010ed810 - std::sys_common::backtrace::_print_fmt::h92d38f701cf42b17
                               at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/std/src/sys_common/backtrace.rs:65:5
   3:        0x1010ed810 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hb33e6e8152f78c95
                               at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/std/src/sys_common/backtrace.rs:44:22
   4:        0x101104bac - core::fmt::write::hd33da007f7a27e39
                               at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/core/src/fmt/mod.rs:1208:17
   5:        0x1010eb788 - std::io::Write::write_fmt::h7edc10723862001e
                               at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/std/src/io/mod.rs:1682:15
   6:        0x1010ed624 - std::sys_common::backtrace::_print::h5e00f05f436af01f
                               at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/std/src/sys_common/backtrace.rs:47:5
   7:        0x1010ed624 - std::sys_common::backtrace::print::h895ee35b3f17b334
                               at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/std/src/sys_common/backtrace.rs:34:9
   8:        0x1010eed98 - std::panicking::default_hook::{{closure}}::h3b7ee083edc2ea3e
                               at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/std/src/panicking.rs:267:22
   9:        0x1010eeaf0 - std::panicking::default_hook::h4e7c2c28eba716f5
                               at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/std/src/panicking.rs:286:9
  10:        0x1010ef3bc - std::panicking::rust_panic_with_hook::h1672176227032c45
                               at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/std/src/panicking.rs:688:13
  11:        0x1010ef1dc - std::panicking::begin_panic_handler::{{closure}}::h0b2d072f9624d32e
                               at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/std/src/panicking.rs:579:13
  12:        0x1010edc78 - std::sys_common::backtrace::__rust_end_short_backtrace::he9abda779115b93c
                               at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/std/src/sys_common/backtrace.rs:137:18
  13:        0x1010eef38 - rust_begin_unwind
                               at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/std/src/panicking.rs:575:5
  14:        0x1011120bc - core::panicking::panic_fmt::h23ae44661fec0889
                               at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/core/src/panicking.rs:64:14
  15:        0x101112394 - core::result::unwrap_failed::h414a6cbb12b1e143
                               at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/core/src/result.rs:1791:5
  16:        0x100ee9c8c - core::result::Result<T,E>::unwrap::h585300c727446024
  17:        0x100f13600 - rust_out::main::_doctest_main_src_genapi_mod_rs_70_0::h46824d8a1a4843df
  18:        0x100f132e8 - rust_out::main::ha12cc177fff9511c
  19:        0x100ee3270 - core::ops::function::FnOnce::call_once::h84bb37f27cbfcd8f
  20:        0x100ee1d40 - std::sys_common::backtrace::__rust_begin_short_backtrace::h813ad797d3d37f95
  21:        0x100ee1e74 - std::rt::lang_start::{{closure}}::h8bfb5e6da05388a2
  22:        0x1010e8a94 - core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &F>::call_once::ha1c2447b9b665e13
                               at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/core/src/ops/function.rs:606:13
  23:        0x1010e8a94 - std::panicking::try::do_call::ha57d6d1e9532dc1f
                               at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/std/src/panicking.rs:483:40
  24:        0x1010e8a94 - std::panicking::try::hca0526f287961ecd
                               at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/std/src/panicking.rs:447:19
  25:        0x1010e8a94 - std::panic::catch_unwind::hdcaa7fa896e0496a
                               at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/std/src/panic.rs:137:14
  26:        0x1010e8a94 - std::rt::lang_start_internal::{{closure}}::h142ec071d3766871
                               at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/std/src/rt.rs:148:48
  27:        0x1010e8a94 - std::panicking::try::do_call::h95f5e55d6f048978
                               at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/std/src/panicking.rs:483:40
  28:        0x1010e8a94 - std::panicking::try::h0fa00e2f7b4a5c64
                               at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/std/src/panicking.rs:447:19
  29:        0x1010e8a94 - std::panic::catch_unwind::h1765f149814d4d3e
                               at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/std/src/panic.rs:137:14
  30:        0x1010e8a94 - std::rt::lang_start_internal::h00a235e820a7f01c
                               at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/std/src/rt.rs:148:20
  31:        0x100ee1e4c - std::rt::lang_start::h6ff56b89212eb3b9
  32:        0x100f13664 - _main



failures:
    src/camera.rs - camera::Camera<Ctrl,Strm,Ctxt>::params_ctxt (line 380)
    src/genapi/mod.rs - genapi (line 8)
    src/genapi/mod.rs - genapi::ParamsCtxt (line 70)

test result: FAILED. 15 passed; 3 failed; 0 ignored; 0 measured; 0 filtered out; finished in 16.28s

error: doctest failed, to rerun pass `-p cameleon --doc`

@bschwind
Copy link
Contributor

Additionally, with that same camera attached, I get an error on the stream example with this branch, whereas I don't get an error on main:

brian cameleon $ cargo run --release --example stream
   Compiling cameleon v0.1.8 (/Users/brian/projects/cameleon/cameleon)
    Finished release [optimized] target(s) in 1.98s
     Running `target/release/examples/stream`
payload received! block_id: 1, timestamp: 356.6832633s
ImageInfo { width: 3088, height: 2076, x_offset: 0, y_offset: 0, pixel_format: BayerRG8, image_size: 6410688 }

payload received! block_id: 2, timestamp: 356.7332606s
ImageInfo { width: 3088, height: 2076, x_offset: 0, y_offset: 0, pixel_format: BayerRG8, image_size: 6410688 }

payload received! block_id: 3, timestamp: 356.7832579s
ImageInfo { width: 3088, height: 2076, x_offset: 0, y_offset: 0, pixel_format: BayerRG8, image_size: 6410688 }

payload received! block_id: 4, timestamp: 356.8332552s
ImageInfo { width: 3088, height: 2076, x_offset: 0, y_offset: 0, pixel_format: BayerRG8, image_size: 6410688 }

payload received! block_id: 5, timestamp: 356.8832525s
ImageInfo { width: 3088, height: 2076, x_offset: 0, y_offset: 0, pixel_format: BayerRG8, image_size: 6410688 }

payload received! block_id: 6, timestamp: 356.9332498s
ImageInfo { width: 3088, height: 2076, x_offset: 0, y_offset: 0, pixel_format: BayerRG8, image_size: 6410688 }

payload received! block_id: 7, timestamp: 356.9832471s
ImageInfo { width: 3088, height: 2076, x_offset: 0, y_offset: 0, pixel_format: BayerRG8, image_size: 6410688 }

payload received! block_id: 8, timestamp: 357.0332444s
ImageInfo { width: 3088, height: 2076, x_offset: 0, y_offset: 0, pixel_format: BayerRG8, image_size: 6410688 }

payload received! block_id: 9, timestamp: 357.08324165s
ImageInfo { width: 3088, height: 2076, x_offset: 0, y_offset: 0, pixel_format: BayerRG8, image_size: 6410688 }

payload received! block_id: 10, timestamp: 357.133239s
ImageInfo { width: 3088, height: 2076, x_offset: 0, y_offset: 0, pixel_format: BayerRG8, image_size: 6410688 }

brian cameleon $ git checkout recv-blocking          
Switched to branch 'recv-blocking'
Your branch is up to date with 'tonari/recv-blocking'.
brian cameleon $ cargo run --release --example stream
   Compiling cameleon v0.1.8 (/Users/brian/projects/cameleon/cameleon)
    Finished release [optimized] target(s) in 1.97s
     Running `target/release/examples/stream`
thread 'main' panicked at 'should receive a payload: InvalidPayload("trailer status indicates error: DataDiscarded")', cameleon/examples/stream.rs:31:14
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Copy link
Contributor

@bschwind bschwind left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's double check the stream example and why it's failing before merging.

@Y-Nak
Copy link
Member

Y-Nak commented Mar 13, 2023

As for the stream error, my first impression is this error is not because of the change.
The Discarded error suggests that the internal camera buffer may overflow because more data is acquired than the transferred data. And I guess this is because of the implementation of the Camera::stop_streaming method.

pub fn stop_streaming(&mut self) -> CameleonResult<()>
where
Ctrl: DeviceControl,
Strm: PayloadStream,
Ctxt: GenApiCtxt,
{
info!("try stopping streaming");
if !self.strm.is_loop_running() {
return Ok(());
}
// Stop streaming loop.
self.strm.stop_streaming_loop()?;
// Disable streaming.
let mut ctxt = self.params_ctxt()?;
expect_node!(&ctxt, "AcquisitionStop", as_command).execute(&mut ctxt)?;
expect_node!(&ctxt, "TLParamsLocked", as_integer).set_value(&mut ctxt, 0)?;
self.ctrl.disable_streaming()?;
info!("stop streaming successfully");
Ok(())
}

At line 362, stop_streaming_loop is called before calling the series of procedures for sending the packet to tell a device to stop its internal acquisition state. So the images taken between line 362 and line 368 are not transferred to the host. As a result, the camera's internal buffer may overflow (This behavior depends on the implementation of the device because some cameras clear their buffer when streaming is disabled).

So this bug would be resolved by calling the stop_streaming_loop call after making sure the camera ends their streaming state. This is achieved just by moving self.strm.stop_streaming_loop()? after self.ctrl.disable_streaming()?.
Also, I think it'd be better to change the self.stop_streaming method to atomic operation.

@strohel
Copy link
Member Author

strohel commented Mar 13, 2023

@bschwind I've run this branch on `dev-lite-build0-portal` and surprisingly it runs fine (expand for logs)
[tonari@dev-lite-build0-portal cameleon]$ cargo run --release --example stream
    Finished release [optimized] target(s) in 0.05s
     Running `target/release/examples/stream`
payload received! block_id: 0, timestamp: 2874961.6804658s
ImageInfo { width: 3088, height: 2076, x_offset: 0, y_offset: 0, pixel_format: BayerRG8, image_size: 6410688 }

payload received! block_id: 1, timestamp: 2874961.7004665s
ImageInfo { width: 3088, height: 2076, x_offset: 0, y_offset: 0, pixel_format: BayerRG8, image_size: 6410688 }

payload received! block_id: 2, timestamp: 2874961.72046715s
ImageInfo { width: 3088, height: 2076, x_offset: 0, y_offset: 0, pixel_format: BayerRG8, image_size: 6410688 }

payload received! block_id: 3, timestamp: 2874961.74046785s
ImageInfo { width: 3088, height: 2076, x_offset: 0, y_offset: 0, pixel_format: BayerRG8, image_size: 6410688 }

payload received! block_id: 4, timestamp: 2874961.7604685s
ImageInfo { width: 3088, height: 2076, x_offset: 0, y_offset: 0, pixel_format: BayerRG8, image_size: 6410688 }

payload received! block_id: 5, timestamp: 2874961.7804692s
ImageInfo { width: 3088, height: 2076, x_offset: 0, y_offset: 0, pixel_format: BayerRG8, image_size: 6410688 }

payload received! block_id: 6, timestamp: 2874961.80046985s
ImageInfo { width: 3088, height: 2076, x_offset: 0, y_offset: 0, pixel_format: BayerRG8, image_size: 6410688 }

payload received! block_id: 7, timestamp: 2874961.82047055s
ImageInfo { width: 3088, height: 2076, x_offset: 0, y_offset: 0, pixel_format: BayerRG8, image_size: 6410688 }

payload received! block_id: 8, timestamp: 2874961.8404712s
ImageInfo { width: 3088, height: 2076, x_offset: 0, y_offset: 0, pixel_format: BayerRG8, image_size: 6410688 }

payload received! block_id: 9, timestamp: 2874961.8604719s
ImageInfo { width: 3088, height: 2076, x_offset: 0, y_offset: 0, pixel_format: BayerRG8, image_size: 6410688 }

Interesting difference between this and your logs from main is that your block_id goes from 1 to 10, but mine goes from 0 to 9.

Probably the first capture always fails for you? Could be also something Mac-specific. The previous stream example silently ignored such errors, but the example as of d7caba6 was rather defensive and panicked on them straight away.

@Y-Nak note that it is the very first capture (receive) that fails for Brian - I've originally read his logs wrong, but he pointed that out.

Anyways, I've changed the panic to logging the warning in the latest commit - please try with that. If that helps I'll also change the code in READMEs I guess.

@Y-Nak
Copy link
Member

Y-Nak commented Mar 13, 2023

Yeah, I realized it. I mean, if Brian ran the stream example on this branch after running it on the main branch without unplugging and plugging the camera, then the first running of the stream example should have affected the camera's internal buffer. Then, the panic got on the second run.

camera.start_streeming() // <- main
...  // <- main
camera.stop_streaming() // <- main: here overflow occurred.

camera.start_streaming() // <- the pr: the buffer state is still overflowed if the camera is not unplugged.
payload_rx.
    recv_blocking().
    expect("should receive a payload"); // <- the pr; panic here affected by the overflow that occurred in the first run.

I guess the problem will be solved if you unplug the camera every time before running the example.

@Y-Nak
Copy link
Member

Y-Nak commented Mar 13, 2023

But this is just speculation; I'm unsure if it's true.

Could be also something Mac-specific.

I think we can exclude the possibility. I basically run tests on Linux, Mac, and Windows. But I didn't find the difference between OS except for usbfs_memory_mb which is described in README.

the example as of d7caba6 was rather defensive and panicked on them straight away.

This is nice for finding some kind of bugs. But also losing some packets sometimes happens without a bug, not so often, though. For example, if many devices are streaming simultaneously on the same USB host controller, then some packets might be lost.

@Y-Nak Y-Nak mentioned this pull request Mar 13, 2023
@Y-Nak
Copy link
Member

Y-Nak commented Mar 13, 2023

@bschwind Could you test #155 in your environment, please?

@bschwind
Copy link
Contributor

bschwind commented Mar 14, 2023

Interesting - I'm receiving approximately random results on each run.

Sometimes all captures fail, sometimes just a few fail, and a lot in between. I don't see any particular patterns.

Re-plugging the camera also doesn't resolve the issue.

The current main branch still captures all 10 frames successfully every time I run it, include re-plugging the camera.

Here are two example runs from this branch:

brian cameleon $ cargo run --release --example stream
    Finished release [optimized] target(s) in 0.07s
     Running `target/release/examples/stream`
payload receive error: invalid payload has been sent: trailer status indicates error: DataDiscarded
payload receive error: invalid payload has been sent: trailer status indicates error: DataDiscarded
payload received! block_id: 7, timestamp: 66.92196625s
ImageInfo { width: 3088, height: 2076, x_offset: 0, y_offset: 0, pixel_format: BayerRG8, image_size: 6410688 }

payload receive error: invalid payload has been sent: trailer status indicates error: DataDiscarded
payload received! block_id: 9, timestamp: 67.02196085s
ImageInfo { width: 3088, height: 2076, x_offset: 0, y_offset: 0, pixel_format: BayerRG8, image_size: 6410688 }

payload receive error: invalid payload has been sent: trailer status indicates error: DataDiscarded
payload received! block_id: 11, timestamp: 67.12195545s
ImageInfo { width: 3088, height: 2076, x_offset: 0, y_offset: 0, pixel_format: BayerRG8, image_size: 6410688 }

payload receive error: invalid payload has been sent: trailer status indicates error: DataDiscarded
payload receive error: invalid payload has been sent: trailer status indicates error: DataDiscarded
payload receive error: invalid payload has been sent: trailer status indicates error: DataDiscarded






brian cameleon $ cargo run --release --example stream
    Finished release [optimized] target(s) in 0.07s
     Running `target/release/examples/stream`
payload receive error: invalid payload has been sent: trailer status indicates error: DataDiscarded
payload received! block_id: 6, timestamp: 69.0639255s
ImageInfo { width: 3088, height: 2076, x_offset: 0, y_offset: 0, pixel_format: BayerRG8, image_size: 6410688 }

payload received! block_id: 7, timestamp: 69.1139228s
ImageInfo { width: 3088, height: 2076, x_offset: 0, y_offset: 0, pixel_format: BayerRG8, image_size: 6410688 }

payload receive error: invalid payload has been sent: trailer status indicates error: DataDiscarded
payload received! block_id: 9, timestamp: 69.2139174s
ImageInfo { width: 3088, height: 2076, x_offset: 0, y_offset: 0, pixel_format: BayerRG8, image_size: 6410688 }

payload receive error: invalid payload has been sent: trailer status indicates error: DataDiscarded
payload receive error: invalid payload has been sent: trailer status indicates error: DataDiscarded
payload receive error: invalid payload has been sent: trailer status indicates error: DataDiscarded
payload receive error: invalid payload has been sent: trailer status indicates error: DataDiscarded
payload receive error: invalid payload has been sent: trailer status indicates error: DataDiscarded

Allows callers to wait for a frame without using futures.

Also bump async-std dependency to 1.12 (unfortunately still doesn't ensure recent-enough
`async-channel` - but I'll fix that in another PR).

Also update the stream example and READMEs with the new method, making it print any receive errors
(but not panic on them) and doing exactly 10 tries (instead of waiting for 10 success payloads).
@strohel
Copy link
Member Author

strohel commented Mar 14, 2023

@strohel strohel requested a review from bschwind March 14, 2023 11:55
Copy link
Contributor

@bschwind bschwind left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! We can dig into the stream errors separately as it's nothing introduced by this PR.

@Y-Nak Y-Nak merged commit 3a2cb95 into cameleon-rs:main Mar 15, 2023
@Y-Nak
Copy link
Member

Y-Nak commented Mar 15, 2023

👍

@strohel strohel deleted the recv-blocking branch March 15, 2023 14:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants